#-*- coding:utf-8 -*-
from django.db import models
from userinfo.models import Userinfo

# Create your models here.
class Relax(models.Model):
    username = models.ForeignKey(Userinfo)
    title = models.TextField()
    body = models.TextField()
    date = models.DateTimeField()

    def getTitleForHome(self):
        linenum = 23
        title_list = []
        title_list.append(self.id)
        if len(self.title) > linenum:
            title_list.append(self.title[0:linenum] +' ...')
        else:
            title_list.append(self.title)
        return title_list

    def __unicode__(self):
        return self.title
    
class Relation(models.Model):
    username = models.ForeignKey(Userinfo,related_name = 'rel_user')
    title = models.ForeignKey(Relax,related_name = 'rel_user')
    date = models.DateTimeField()
    text = models.TextField()

    def __unicode__(self):
        return '%s --- %s' % (self.title.title,self.text)
    
class JoinUs(models.Model):
    username = models.ForeignKey(Userinfo)
    title = models.ForeignKey(Relax)
    date = models.DateTimeField()
        
    def __unicode__(self):
        return '%s --- %s' % (self.title.title,self.username.username)